﻿using Microsoft.Win32;

namespace NoMvvm.Wpf
{
    /// <summary>
    /// Class implementing a default DialogService, inherit and override dialogs to customize
    /// </summary>
    public class DefaultDialogService : IDialogService
    {
        /// <summary>
        /// Override to setup a custom OpenFileDialog
        /// </summary>
        protected virtual OpenFileDialog OpenFileDialog
        {
            get { return new OpenFileDialog(); }
        }

        /// <summary>
        /// Override to setup a custom SaveFileDialog
        /// </summary>
        protected virtual SaveFileDialog SaveFileDialog
        {
            get { return new SaveFileDialog(); }
        }

        /// <summary>
        /// Open a file via OpenFileDialog
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool OpenFile(out string path)
        {
            var dialog = OpenFileDialog;
            var result = dialog.ShowDialog().GetValueOrDefault();
            path = dialog.FileName;
            return result;
        }

        /// <summary>
        /// Save a file via SaveFileDialog
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool SaveFile(out string path)
        {
            var dialog = SaveFileDialog;
            var result = dialog.ShowDialog().GetValueOrDefault();
            path = dialog.FileName;
            return result;
        }
    }
}
